package com.lgx.mall.web.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lgx.common.web.Pagination;
import com.lgx.mall.core.service.IProductService;
import com.lgx.mall.core.vo.ProductVO;
import com.lgx.mall.view.service.IWebPageDetailService;

/**
 * 共享名品
 * 
 * @author acer
 *
 */
@Controller
@RequestMapping("/famous")
public class FamousController {

	@Autowired
	private IWebPageDetailService webPageDetailService;
	
	@Autowired
	private IProductService productService;
	
	public IProductService getProductService() {
		return productService;
	}

	public void setProductService(IProductService productService) {
		this.productService = productService;
	}

	public IWebPageDetailService getWebPageDetailService() {
		return webPageDetailService;
	}

	public void setWebPageDetailService(IWebPageDetailService webPageDetailService) {
		this.webPageDetailService = webPageDetailService;
	}

	@RequestMapping("/index.htm")
	public String index(HttpServletRequest request,HttpServletResponse response){
		
		return "famous/index";
	}
	
	@RequestMapping("/head.ftl")
	public String head(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		return "famous/head";
	}
	/**
	 * 名品推荐区域 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/famous-recom.ftl")
	public String famousRecom(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		long categoryId = 120;
		List<ProductVO> details1 = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details1", details1);
		
		return "famous/famous-recom";
	}
	
	/**
	 * 名品分类 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/famous-brand.ftl")
	public String famousBrand(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		
		long categoryId = 121;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		
		List<Pagination> pages = new ArrayList<Pagination>();
		
		for(ProductVO vo : details){
			long cId = 0;
			if(!StringUtils.isEmpty(vo.getEntityId()))cId = Long.parseLong(vo.getEntityId());
			
			Pagination page = this.productService.findProductByCategory(null, 3, cId, 0,null,null,20,1);
			pages.add(page);
		}
		
		request.setAttribute("pages", pages);
		return "famous/famous-brand";
	}
	/**
	 *  名品商家logo列表 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/famous-logo.ftl")
	public String famousLogo(HttpServletRequest request,HttpServletResponse response){
		String path = request.getContextPath();
		String basePath = request.getScheme() + "://"
				+ request.getServerName() + ":" + request.getServerPort()
				+ path + "/";
		request.setAttribute("basePath", basePath);
		

		long categoryId = 122;
		List<ProductVO> details = this.webPageDetailService.findProductVOByAreaAndCid(null, categoryId);
		request.setAttribute("details", details);
		
		return "famous/famous-logo";
	}
}
